package com.chaihu.bean.entity.center;

import com.chaihu.bean.dto.order.RouteDto;
import io.micrometer.core.instrument.util.StringUtils;
import lombok.Data;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 路由处理
 * AppId 和 服务之间的关系
 * Created by wuxw on 2018/4/14.
 */
@Data
public class AppRoute extends RouteDto {

    //掩码
    private String securityCode;
    private String whileListIp;
    private String blackListIp;
    //白名单
    private List<String> whileListIpList = new ArrayList<String>();

    //黑名单
    private List<String> blackListIpList = new ArrayList<String>();

    //服务
    private AppService appService;

    private String remark;

    private String name;
    private String businessTypeCd;
    private String isInstance;
    private String messageQueueName;
    private String method;
    private String provideAppId;
    private Integer retryCount;
    private Integer seq;
    private String serviceCode;
    private Integer timeout;
    private String url;


    public AppRoute init() {
        if (StringUtils.isNotEmpty(this.whileListIp)) {
            String[] listIps = this.getWhileListIp().split(";");
            this.whileListIpList.addAll(Arrays.asList(listIps));
        }
        if (StringUtils.isNotEmpty(this.blackListIp)) {
            String[] listIps = this.getBlackListIp().split(";");
            this.blackListIpList.addAll(Arrays.asList(listIps));
        }
        this.setAppService(AppService.newInstance().builder(this));
        return this;
    }


}
